package com.szxy.backend.item.controller;

import com.szxy.backend.item.service.ItemParamService;
import com.szxy.pojo.TbItemParam;
import com.szxy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.awt.image.RescaleOp;

/**
 * @Auther:zwer
 * @Date:2019/9/7 16:59
 * @Description:com.szxy.backend.item.controller
 * @Version:1.0
 **/
@RestController
@RequestMapping("/backend/itemParam")
public class ItemParamController {

    @Autowired
    private ItemParamService itemParamService;

    /**
     * 查询商品规格参数模板
     * @param itemCatId
     * @return
     */
    @GetMapping("/selectItemParamByItemCatId/{itemCatId}")
    public Result selectItemParamByItemCatId(@PathVariable Long itemCatId){
            try{
                return this.itemParamService.selectItemParamByItemCatId(itemCatId);
            }catch (Exception e){
                e.printStackTrace();
            }
            return Result.build(500,"查询商品规格参数模板出错");
    }

    @GetMapping("/selectItemParamAll")
    public Result selectItemParamAll(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "30") Integer rows){
        try {
            return this.itemParamService.selectItemParamAll(page,rows);
        }catch (Exception e){
            e.printStackTrace();
        }
        return Result.build(500,"error");
    }

    @PostMapping("/insertItemParam")
    public Result insertItemParam(TbItemParam itemParam){
        try {
            return this.itemParamService.insertItemParam(itemParam);
        }catch (Exception e){
            e.printStackTrace();
        }
        return Result.build(500,"error");
    }

    @GetMapping("/deleteItemParamById")
    public Result   deleteItemParamById(Long id){
        try {
            return this.itemParamService.deleteItemParamById(id);
        }catch (Exception e){
            e.printStackTrace();
        }
        return Result.build(500,"error");
    }


}
